package edu.online.dal;

import edu.online.entity.TimeItemEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface TimeItemEntityMapper {
    @Delete({
        "delete from timeitem",
        "where TimeItemID = #{timeitemid,jdbcType=CHAR}"
    })
    int deleteByPrimaryKey(String timeitemid);

    @Insert({
        "insert into timeitem (TimeItemID, WeekDay, ",
        "LessonTime)",
        "values (#{timeitemid,jdbcType=CHAR}, #{weekday,jdbcType=SMALLINT}, ",
        "#{lessontime,jdbcType=TIMESTAMP})"
    })
    int insert(TimeItemEntity record);

    @InsertProvider(type=TimeItemEntitySqlProvider.class, method="insertSelective")
    int insertSelective(TimeItemEntity record);

    @Select({
        "select",
        "TimeItemID, WeekDay, LessonTime",
        "from timeitem",
        "where TimeItemID = #{timeitemid,jdbcType=CHAR}"
    })
    @Results({
        @Result(column="TimeItemID", property="timeitemid", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="WeekDay", property="weekday", jdbcType=JdbcType.SMALLINT),
        @Result(column="LessonTime", property="lessontime", jdbcType=JdbcType.TIMESTAMP)
    })
    TimeItemEntity selectByPrimaryKey(String timeitemid);

    @UpdateProvider(type=TimeItemEntitySqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(TimeItemEntity record);

    @Update({
        "update timeitem",
        "set WeekDay = #{weekday,jdbcType=SMALLINT},",
          "LessonTime = #{lessontime,jdbcType=TIMESTAMP}",
        "where TimeItemID = #{timeitemid,jdbcType=CHAR}"
    })
    int updateByPrimaryKey(TimeItemEntity record);
}